<template>
	<view class="inspectContent">
		<view class="upper">
			<commonNavBar title="风险评级" :showSearch="true" @search="open"></commonNavBar>
			<view class="step">
				<view v-for="(tabs, index) in stepList" :key="index" @click="stepActive(index)">
					<view :class="{ 'active': tabIndex == index }">
						{{ tabs.step }}
					</view>
				</view>
			</view>
		</view>
		<view class="centre">
			<z-paging ref="paging" autowire-list-name="inspectList" autowire-query-name="listData">
				<view class="li" v-for="(list, index) in inspectList" :key="index">
					<view class="float">{{ list.PROCESS_NAME }}</view>
					<view class="h1">{{ index + 1 }}.{{ list.COMPANY_NAME }}</view>
					<!-- <view class="h2">业态:{{ list.RISK_LEVEL }}</view> -->
					<view class="h2">风险等级:{{ list.RISK_LEVEL }}</view>
					<view class="h2">许可证号:{{ list.LICENSE }}</view>
					<view class="h2">所属区局:{{ list.DEPT_QU_NAME }}</view>
					<view class="h2">监管单位:{{ list.DEPT_NAME }}</view>
					<view class="h2">企业地址:{{ list.ADDRESS }}</view>
					<view class="h2">联系人:{{ list.CONTACT }}</view>
					<view class="h2">联系电话:{{ list.CONTACT_PHONE == 'undefined' ? '' : list.CONTACT_PHONE }}</view>
					<view class="order" v-if="tabIndex === 0">
						<!-- :class="( list.STATIC_STATUS == '0' ? 'special' : 'Active')" -->
						<view class="dd"
							@tap.stop="addInspect(list.COMPANY_ID, list.IS_AUTHORITY, list.STATIC_STATUS, 'static', list.STATIC_ID)"
							:class="{
								special: list.STATIC_STATUS == '0',
								Advent: list.STATIC_STATUS != '0' && list.ADVENT_STATUS == 'L',
								Active: list.STATIC_STATUS != '0' && list.ADVENT_STATUS != 'L',
								noAuthority: list.IS_AUTHORITY != '1' && list.STATIC_STATUS != '0'
							}">
							<view class="dd1">
								<text>静态评分</text>
								<text v-if="list.ADVENT_STATUS != 'L'"
									v-text="list.STATIC_STATUS == '0' ? '已评分' : '未评分'"></text>
								<text v-if="list.ADVENT_STATUS == 'L'"
									v-text="list.STATIC_STATUS == '0' ? '已评分' : '未评分(临期)'"></text>
							</view>
							<view class="triangle"></view>
						</view>
						<!-- :class="( list.DYNAMIC_STATUS == '0' ? 'special' : 'Active')" -->
						<view class="dd" v-if="list.RISK_LEVEL == '' || list.RISK_LEVEL == undefined"
							@tap.stop="addInspect(list.COMPANY_ID, list.IS_AUTHORITY, list.DYNAMIC_STATUS, 'dynamic', list.DYNAMIC_ID)"
							:class="{
								special: list.DYNAMIC_STATUS == '0',
								Advent: list.DYNAMIC_STATUS != '0' && list.ADVENT_STATUS == 'L',
								Active: list.DYNAMIC_STATUS != '0' && list.ADVENT_STATUS != 'L',
								noAuthority: list.IS_AUTHORITY != '1' && list.DYNAMIC_STATUS != '0'
							}">
							<view class="dd1">
								<text>动态初次评分</text>
								<text v-if="list.ADVENT_STATUS != 'L'"
									v-text="list.DYNAMIC_STATUS == '0' ? '已评分' : '未评分'"></text>
								<text v-if="list.ADVENT_STATUS == 'L'"
									v-text="list.DYNAMIC_STATUS == '0' ? '已评分' : '未评分(临期)'"></text>
							</view>
							<view class="triangle"></view>
						</view>
						<!-- :class="( list.DYNAMIC_STATUS == '0' ? 'special' : 'Active')" -->
						<view class="dd" v-else
							@tap.stop="addInspect(list.COMPANY_ID, list.IS_AUTHORITY, list.DYNAMIC_STATUS, 'dynamic', list.DYNAMIC_ID)"
							:class="{
								special: list.DYNAMIC_STATUS == '0',
								Advent: list.DYNAMIC_STATUS != '0' && list.ADVENT_STATUS == 'L',
								Active: list.DYNAMIC_STATUS != '0' && list.ADVENT_STATUS != 'L',
								noAuthority: list.IS_AUTHORITY != '1' && list.DYNAMIC_STATUS != '0'
							}">
							<view class="dd1">
								<text>动态初次评分</text>
								<text v-if="list.ADVENT_STATUS != 'L'"
									v-text="list.DYNAMIC_STATUS == '0' ? '已评分' : '未评分'"></text>
								<text v-if="list.ADVENT_STATUS == 'L'"
									v-text="list.DYNAMIC_STATUS == '0' ? '已评分' : '未评分(临期)'"></text>
							</view>
							<view class="triangle"></view>
						</view>
					</view>
					<view class="order" v-if="tabIndex === 1">
						<!-- 经营使用 -->
						<!-- 已申请的时候显示 -->
						<view class="dd special"
							@tap.stop="showInspect(list.COMPANY_ID, list.IS_AUTHORITY, list.EXAMINE_RESULT, list.SUP_PROCESS, list.LEVEL_ID)"
							v-if="list.CHECK_STATUS == '3' && list.EXAMINE_RESULT != '1'">
							<view class="dd1">
								<text v-text="'已申请'"></text>
							</view>
							<view class="triangle"></view>
						</view>
						<view class="dd  "
							@tap.stop="jyAddLevel(list.COMPANY_ID, list.IS_AUTHORITY, list.AUDIT_AUTH, list.CHECK_STATUS, 'level', list.EXAMINE_RESULT, list.LEVEL_ID)"
							:class="(statusFilter(list.CHECK_STATUS, list.EXAMINE_RESULT, list.ADVENT_STATUS))">
							<view class="dd1">
								<!-- 生产企业只用初次评级，经营企业一直使用此评级 -->
								<text v-text="'已完成等级评定'" v-if="list.CHECK_STATUS == '99'"></text>
								<text v-text="'评定等级(临期)'"
									v-if="list.CHECK_STATUS == '2' && (list.EXAMINE_RESULT == '2' || list.EXAMINE_RESULT == '0') && list.ADVENT_STATUS == 'L'"></text>
								<text v-text="'评定等级'"
									v-if="list.CHECK_STATUS == '2' && (list.EXAMINE_RESULT == '2' || list.EXAMINE_RESULT == '0') && list.ADVENT_STATUS != 'L'"></text>
								<text v-text="'待审核'"
									v-if="list.CHECK_STATUS == '3' && list.EXAMINE_RESULT == '2'"></text>
								<text v-text="'不通过'"
									v-if="list.CHECK_STATUS == '3' && list.EXAMINE_RESULT == '0'"></text>
								<text v-text="'已评级'"
									v-if="list.CHECK_STATUS == '0' && list.EXAMINE_RESULT == '1'"></text>
							</view>
							<view class="triangle"></view>
						</view>
						<!-- 审核通过之后显示 -->
						<view class="dd special"
							@tap.stop="showExamine(list.COMPANY_ID, list.EXAMINE_RESULT, list.SUP_PROCESS, list.LEVEL_ID)"
							v-if="list.CHECK_STATUS == '0' && list.EXAMINE_RESULT == '1'">
							<view class="dd1">
								<text v-text="'已审核'"></text>
							</view>
							<view class="triangle"></view>
						</view>
					</view>
				</view>
			</z-paging>
			<CommonSearchCompontVue ref="CommonSearchCompontVueRef" @seacharResult="seacharResult"
				:typeWhiteList="typeWhite" :showTime="tabIndex == 1" :showMarkStatus="tabIndex == 0"
				:showRateStatus="tabIndex == 1" :showSearchCompont="showSearchCompont"></CommonSearchCompontVue>
		</view>
		<view class="fixed">当前已搜索到{{ total }}条数据</view>
	</view>
</template>

<script>
import CommonSearchCompontVue from '../../components/CommonSearchCompont.vue'
import commonNavBar from '@/components/CommonNavBar.vue';

export default {
	components: {
		commonNavBar,
		CommonSearchCompontVue
	},
	data() {
		return {
			stepList: [{
				step: '风险分级',
				active: true
			}, {
				step: '等级评定',
				active: false
			}],
			tabIndex: 0,
			showSearchCompont: false,
			inspectList: [],
			total: 0,
			searchParams: {
				companyName: '', //企业名称
				firstType: '', //一级业态
				twoType: '', //二级业态
				companyIndex: 0, // 企业环节
				companyLevel: '',//安全等级
				checkStatus: '', // 检查情况
				companyProcess: '', // 企业环节
				supervisePerson: '', // 监管人
				existPeriphery: '', // 是否校园周边
				existWholesaleAgricultura: '', // 是否农产品批发
				existEx: '', // 是否异常主体
				onlyPrePackaging: '', // 仅售预包装食品
				haveSpecialFood: '', // 是否有特殊食堂
				address: '', // 企业地址
				startTime: '',
				endTime: '',
				pageNum: 1,
				pageSize: 10,
			},
			isLoading: false,
			typeWhite: "spxs,cyfw"
		}
	},
	onLoad(options) {
		this.tabIndex = options.tabIndex == undefined ? 0 : parseInt(options.tabIndex);
		this.$set(this.searchParams, 'checkStatus', options.inspectStatus == undefined ? '' : parseInt(options.inspectStatus));
		for (var i = 0; i < this.stepList.length; i++) {
			this.$set(this.stepList[i], "active", false);
		}
		this.$set(this.stepList[options.tabIndex], "active", true);
	},
	onReady() {
		this.$refs.CommonSearchCompontVueRef.setCheckStatus(this.searchParams.checkStatus + "");
		//this.$refs.paging.reload();
	},
	methods: {
		open() {
			this.showSearchCompont = true
		},
		seacharResult(e) {
			//检索条件点击确定或者删除的时候在执行
			this.showSearchCompont = false;
			if (e.search) {
				this.searchParams = e;
				this.$refs.paging.reload();
			}
		},
		goBack() {
			uni.navigateBack();
		},
		async listData(pageNo, pageSize, reload) {
			this.searchParams.pageNum = pageNo;
			this.searchParams.pageSize = pageSize;
			this.searchParams.type = this.tabIndex;
			try {
				const res = await uni.$api.getRiskList(this.searchParams);
				this.total = res.data.data.total;
				this.$refs.paging.completeByKey(res.data.data.records, this.tabIndex);
				this.total = res.data.data.total
				this.isLoading = false;
			} catch (error) {
				this.$refs.paging.complete(false);
				this.isLoading = false;
			}

		},
		stepActive(index) {
			if (this.isLoading) {
				return; // 如果数据正在加载，直接返回
			}
			this.tabIndex = index;
			this.isLoading = true;
			this.$refs.paging.reload();
		},
		/**
		 * @param {Object} companyId 企业id
		 * @param {Object} status 状态
		 * @param {Object} type 类型
		 * @param {Object} examineResult  审核结果（等级评定功能使用）
		 * @param {Object} supProcess  企业所属环节
		 */
		addInspect(companyId, isAuthority, status, type, infoId) {
			const that = this;
			if (isAuthority != '1' && status == '2') {
				//没有权限操作
				uni.showToast({
					icon: 'error',
					title: '无操作权限',
					duration: 4000
				})
				return;
			}
			//风险分级
			if (type == 'static') {
				//静态评分
				if ("0" == status) {
					//已完成评分
					uni.navigateTo({
						url: '/pages/risk/riskStaticRatingResult?staticScoringId=' + infoId
					})
				} else {
					uni.navigateTo({
						url: '/pages/risk/riskStaticRating?companyId=' + companyId,
						events: {
							// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
							reloadList: function (data) {
								that.$refs.paging.reload();
							}
						}
					})
				}
			} else if (type == 'dynamic') {
				//动态评分
				if ("0" == status) {
					//已完成评分
					uni.navigateTo({
						url: '/pages/risk/riskDynamicRatingResult?dynamicScoringId=' + infoId
					})
				} else {
					//未完成评分
					uni.navigateTo({
						url: '/pages/risk/riskDynamicRating?companyId=' + companyId,
						events: {
							// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
							reloadList: function (data) {
								that.$refs.paging.reload();
							}
						}
					})
				}
			}
		},
		jyAddLevel(companyId, isAuthority, auditAuth, status, type, examineResult, riskLevelId) {
			//list.COMPANY_ID, list.IS_AUTHORITY,list.AUDIT_AUTH,list.CHECK_STATUS,'level',list.EXAMINE_RESULT
			const that = this;
			//经营企业新增评级
			if (status == '2' && examineResult != '1') {
				//经营企业评级
				if (isAuthority != '1') {
					//没有权限操作
					uni.showToast({
						icon: 'error',
						title: '无操作权限',
						duration: 4000
					})
					return;
				}
				uni.navigateTo({
					url: '/pages/risk/riskLevelRating?companyId=' + companyId + "&detail=false" + "&first=true",
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						reloadList: function (data) {
							that.$refs.paging.reload();
						}
					}
				})
			} else if (status == '3' && examineResult == '2') {
				//评定审核
				if (auditAuth != '1') {
					//没有权限操作
					uni.showToast({
						icon: 'error',
						title: '无操作权限',
						duration: 4000
					})
					return;
				}
				uni.navigateTo({
					url: '/pages/risk/riskLevelExamine?riskLevelId=' + riskLevelId + "&detail=false" + "&first=true",
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						reloadList: function (data) {
							that.$refs.paging.reload();
						}
					}
				})
			} else if (status == '0' && examineResult == '0') {
				//查看评定审核
				uni.navigateTo({
					url: '/pages/risk/riskLevelExamine?riskLevelId=' + riskLevelId + "&detail=true" + "&first=true",
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						reloadList: function (data) {
							that.$refs.paging.reload();
						}
					}
				})
			} else if (status == '0' && examineResult == '1') {
				//已经评级 审核通过就去查看评级信息
				uni.navigateTo({
					url: '/pages/risk/riskLevelRatingResult?riskLevelId=' + riskLevelId + "&detail=true" + "&first=true"
				})
			}
		},
		showInspect(companyId, isAuthority, examineResult, supProcess, riskLevelId) {
			const that = this;
			//已经申请完成的,如果是审核通过或者待审核则是查看详情,否则是进行重新申请
			//经营企业
			console.log("examineResult", examineResult);
			if (examineResult != '0') {
				uni.navigateTo({
					url: '/pages/risk/riskLevelRatingResult?riskLevelId=' + riskLevelId
				})
			} else {
				if (isAuthority != '1') {
					//没有权限操作
					uni.showToast({
						icon: 'error',
						title: '无操作权限',
						duration: 4000
					})
					return;
				}
				uni.navigateTo({
					url: '/pages/risk/riskLevelRating?riskLevelId=' + riskLevelId,
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						reloadList: function (data) {
							that.$refs.paging.reload();
						}
					}
				})
			}

		},
		showExamine(companyId, examineResult, supProcess, riskLevelId) {
			//查看审核信息
			//已经审核 不管通过不通过都去审核历史
			uni.navigateTo({
				url: '/pages/risk/riskLevelExamine?riskLevelId=' + riskLevelId + "&detail=true"
			})
		},
		close() {
			this.$refs.popup.close()
		},
		cancellation() {
			this.close()
		},
		statusFilter(status, examineResult, adventStatus) {
			//判断任务状态 	'special' : 'Active'
			if (status == '2' && (examineResult == undefined || examineResult == '0' || examineResult == '2')) {
				if (adventStatus == 'L') {
					return 'Advent'
				}
				return 'Active';
			} else if (status == '3' && examineResult == '2') {
				return 'Active';
			} else if (status == '3' && examineResult == '0') {
				return 'Danger';
			}
			return 'special';
		}
	},
	watch: {

	},
}
</script>

<style lang="scss">
.inspectContent {
	background: #F9F9F9;
	height: calc(100vh - 195rpx);

	.upper {
		position: fixed;
		z-index: 1;
		top: 0;
		left: 0;
		width: 100%;

		.step {
			display: flex;
			justify-content: space-around;
			height: 80rpx;
			line-height: 80rpx;
			background: #F9F9F9;

			view {
				position: relative;
				font-size: 25rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;

				&.active {
					color: #0552A9;

					&::before {
						display: block;
						content: "";
						position: absolute;
						left: 50%;
						bottom: 0%;
						transform: translate(-50%, 0%);
						width: 100rpx;
						height: 5rpx;
						background: #0552A9;
					}
				}
			}
		}
	}

	.centre {
		margin: 195rpx 0 0 0;
		padding: 0 17.5rpx;
		height: calc(100vh - 280rpx);
		overflow-x: hidden;

		.z-paging-content-fixed {
			padding: 195rpx 0 0 0;
		}

		.li {
			background: linear-gradient(180deg, #FFFFFF 0%, #FFFFFF 100%);
			box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(0, 0, 0, 0.05);
			border-radius: 15rpx;
			padding: 30rpx 30rpx 15rpx 28rpx;
			position: relative;
			margin: 13rpx 20rpx 0;

			.float {
				position: absolute;
				top: 0;
				right: 0;
				// width: 97rpx;
				padding: 0 10rpx;
				height: 46rpx;
				line-height: 46rpx;
				background: linear-gradient(180deg, #5DA1FF 0%, #0054C9 100%);
				border-radius: 0rpx 11rpx 0rpx 11rpx;
				font-size: 18rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				text-align: center;
			}

			.h1 {
				font-size: 24rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #333333;
				line-height: 1;
				margin: 0 0 14rpx 0;
			}

			.h2 {
				font-size: 19rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
				line-height: 1;
				margin: 12rpx auto;
			}

			.order {
				margin: 24rpx auto 0;
				white-space: nowrap;
				overflow-x: auto;

				.dd {
					padding: 0px 8px;
					min-width: 150rpx;
					height: 55rpx;
					border-radius: 9rpx;
					border: 1rpx solid #979797;
					font-size: 20rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 700;
					color: #A1A1A1;
					position: relative;
					text-indent: -10rpx;
					display: inline-block;
					text-align: center;

					.dd1 {
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;
						height: 55rpx;
					}



					.triangle {
						width: 0;
						height: 0;
						border-top: 8rpx solid transparent;
						border-bottom: 8rpx solid transparent;
						border-left: 10rpx solid #A1A1A1;
						position: absolute;
						top: 50%;
						right: 4rpx;
						transform: translate(-50%, -50%);
					}

					&+.dd {
						margin: 0 0 0 12rpx;
					}

					&.Active {
						border: 1px solid #f9cb40;
						background: #f9cb40;
						color: #fff;

						.triangle {
							border-left: 10rpx solid #fff;
						}
					}


					&.Danger {
						border: 1px solid #F95E5A;
						background: #F95E5A;
						color: #fff;

						.triangle {
							border-left: 10rpx solid #fff;
						}
					}

					&.special {
						border: 1px solid #00BE8C;
						background: #00BE8C;
						color: #fff;

						.triangle {
							border-left: 10rpx solid #fff;
						}
					}

					&.Advent {
						border: 1px solid #f46513;
						background: #f46513;
						color: #fff;

						.triangle {
							border-left: 10rpx solid #fff;
						}
					}

					&.noAuthority {
						opacity: .2;
					}
				}
			}
		}
	}

	.fixed {
		position: fixed;
		left: 50%;
		bottom: 26rpx;
		transform: translate(-50%, 0);
		width: 100%;
		text-align: center;
		font-size: 18rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #A7A7A7;
	}

	.popupContent {
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 0 0;

		.uni-datetime-picker {
			width: 100%;
		}

		.title {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			background: url('../../static/img/popupTitle.png') no-repeat center center;
			background-size: cover;
			font-size: 25rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			text-indent: 45rpx;
		}

		.ul {

			.li {
				padding: 0 45rpx;
				margin: 0 auto;
				display: flex;
				justify-content: space-between;
				align-items: center;
				min-height: 68rpx;
				line-height: 68rpx;
				border-bottom: 1px solid #d6d6d6;

				.left {
					font-size: 21rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #333333;
				}

				.right {

					input {
						font-size: 21rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						width: 460rpx;
						text-indent: 20rpx;
					}

					.placeholder-class {
						color: #999999;
					}

					.uni-stat__select {
						width: 460rpx;

						/deep/.uni-select {
							border: none;
						}
					}

					.uni-date {
						width: 460rpx;

						/deep/.uni-date-editor--x {
							border: none;
						}
					}
				}

				&:nth-child(odd) {
					background: #F9F9F9;
				}

				&:last-child {
					border-bottom: none;
				}
			}

			.li:last-child {
				/deep/.uni-select__selector {
					top: initial;
				}

				/deep/.uni-popper__arrow {
					display: none;
				}
			}
		}

		.button {
			margin: 58rpx auto 0;
			padding: 0 95rpx 24rpx 95rpx;
			display: flex;

			button {
				width: 269rpx;
				height: 55rpx;
				line-height: 55rpx;
				background: #0552A9;
				border-radius: 10rpx;
				font-size: 20rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;

				&.determine {
					color: #fff;
				}

				&.cancellation {
					background: none;
					border: 1rpx solid #979797;
					color: #979797;
				}
			}
		}
	}
}

.navigator-check {
	position: absolute;
	width: 100rpx;
	height: 100rpx;
	z-index: 9;
	right: 0px;
	bottom: 0px;
	border-radius: 0rpx 0rpx 15rpx 0rpx;
}
</style>
